package cate.game.activity.limitshop.msg;

import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.activity.limitshop.LimitShopActivity;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBLimitShopActivity;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ClientMsg(title = "限时商店-购买 请求")
public class LimitShopActivityBuyReq implements MsgInput {
    @NoteField("功能ID")
    public int funcId;
    @NoteField("配置ID")
    public int tid;
    @NoteField("数量")
    public int num;

    @Override
    public MsgConfig conf() {
        return MsgIdBLimitShopActivity.LIMIT_SHOP_ACTIVITY_BUY_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        if (num <= 0 || num > 9999) {
            log.error("[LimitShopActivityBuyReq] 玩家ID:{} 发送了非法的物品数量!", cc.getRole().getBase().uid);
            return;
        }
        LimitShopActivity gift = cc.getRole().getActivity().getEnableActivitySingle(funcId);
        if (gift == null) {
            cc.getRole().getGame().notice.message(cc.getRole(), "活动未开启");
            return;
        }
        GameResult<LimitShopActivity> r = gift.buyItem(tid, num);
        if (!r.ok()) {
            game.notice.message(cc.getRole(), r.message);
        }else {
            gift.noticeUpdate();
        }
    }
}
